const {
  toUrl,
  globalData
} = getApp();
import {
  request
} from "@/utils/request";

Page({
  toUrl,
  data: {
    list: [],
    page: 1,
    isEnd: false,
    count: 0,
    globalData
  },
  carList() {
    if (this.data.page > 1 && this.data.page > this.data.count) {
      this.setData({
        isEnd: true,
      });
      return;
    }
    wx.showLoading();
    let data = {
      page: this.data.page,
    };
    request("carapi/payrecords", {
      data
    }).then((res) => {
      wx.hideLoading();
      if (res.errcode == 1) {
        let list = this.data.list
        if (this.data.page > 1) {
          res.data.map((it) => {
            list.push(it)
          })

          this.setData({
            list,
            count: res.data.length,
            page: ++this.data.page
          });
        } else {
          this.setData({
            list: res.data,
            count: res.data.length,
            page: ++this.data.page
          });
        }

      } else {
        wx.showToast({
          title: res.message,
        });
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.carList();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    let isEnd = this.data.isEnd;
    if (isEnd) {
      return;
    } else {
      this.carList();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});